﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace Zhuang.WinForm.ControlLibrary.UserControls
{
    public partial class SummaryText : UserControl
    {
        DataGridView dgv;
        string columnName;


        public SummaryText()
        {
            InitializeComponent();
       
        }

        public void Initialize(DataGridView dgv, string columnName)
        {
            this.dgv = dgv;
            this.columnName = columnName;
            lbName.Text = string.Format(lbName.Text, dgv.Columns[columnName].HeaderText);

            lbValue.Location = new Point(lbName.Location.X + lbName.Width + 10, lbValue.Location.Y);
        }

        public void Calculate()
        {
            decimal value = 0.00m;

            foreach (DataGridViewRow dgvr in dgv.Rows)
            {
                value = value + Convert.ToDecimal(dgvr.Cells[columnName].Value);

            }

            lbValue.Text=value.ToString("N2");

        }

        private void SummaryText_Load(object sender, EventArgs e)
        {
            
        }
    }


}
